package com.example.blogsystem.controller;

import com.example.blogsystem.constant.Constant;
import com.example.blogsystem.model.Result;
import com.example.blogsystem.model.User;
import com.example.blogsystem.service.UserService;
import com.example.blogsystem.utils.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /*
    用户名6-15位
    密码6-15位
 */
    @RequestMapping("/signIn")
    public Result<Object> register(String userName, String password) {
        return userService.registerLogic(userName, password);
    }

    //验证用户
    @RequestMapping("/login")
    public Result<String> checkUser(String userName, String password) {
        return userService.checkUser(userName, password);
    }

    //获取当前登录用户信息
    @RequestMapping("/getUserInfo")
    public Result<User> getUserInfo(HttpServletRequest request) {
        return userService.getUserInfoLogic(request);
    }

    //获取当前作者信息
    @RequestMapping("/getAuthorInfo")
    public Result<User> getAuthorInfo(Integer blogId) {
        Result<User> result = new Result<>();
        User user = userService.queryAuthorByBlogId(blogId);
        if(user == null) {
            return result.fail("用户信息为空");
        }
        return result.success(user);
    }




}
